﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace BangkokSteel
{
    public partial class frmMainForm : Form
    {

        private List<MainFormListener> registerdForms = new List<MainFormListener>();

        public frmMainForm()
        {
            InitializeComponent();
        }

        private void mnuTest_Click(object sender, EventArgs e)
        {
            frmFormTest form = new frmFormTest();
            AddTabPage(form, "ทดสอบ");
        }

        private void AddTabPage(Form form, string tabName)
        {
            foreach(TabPage page in tabControl1.TabPages)
            {
                if (page.Text.Equals(tabName))
                {
                    tabControl1.SelectedTab = page;
                    return;
                }
            }

            TabPage tabPage = new TabPage(tabName);

            form.TopLevel = false; // This is most Important
            form.FormBorderStyle = FormBorderStyle.None;
            // form.Width = this.tabControl1.Width;
            tabPage.Controls.Add(form);
            form.Dock = DockStyle.Fill;
            form.Show();

            tabControl1.TabPages.Add(tabPage);
            tabControl1.SelectedTab = tabPage;

            // For Focus on First Control 
            form.Controls[0].Select();

            //MainFormListener listener = (MainFormListener)form;
            //listener.onTabPageAdded();
        }

        private void frmMainForm_Load(object sender, EventArgs e)
        {

        }


        private void mnuPurchaseOrder_Click(object sender, EventArgs e)
        {
            frmPurchaseOrderAddnew form = new frmPurchaseOrderAddnew(tabControl1);
            AddTabPage(form, "สั่งซื้อสินค้า");
        }

        private void mnuReceiveOrder_Click(object sender, EventArgs e)
        {
            frmReceiveOrderAddnew form = new frmReceiveOrderAddnew(tabControl1);
            AddTabPage(form, "รับสินค้า");
        }

        private void mnuReceiveCondition_Click(object sender, EventArgs e)
        {
            frmRecieveCondition form = new frmRecieveCondition(tabControl1);
            AddTabPage(form, "เงื่อนไขการรับสินค้า");
        }

        private void mnuVat_Click(object sender, EventArgs e)
        {
            frmVat form = new frmVat(tabControl1);
            AddTabPage(form, "Vat");
        }

        private void mnuPaymentTerm_Click(object sender, EventArgs e)
        {
            frmPaymentTerm form = new frmPaymentTerm(tabControl1);
            AddTabPage(form, "เครดิต");            
        }

        private void mnuProductCategory_Click(object sender, EventArgs e)
        {
            frmProductCategory form = new frmProductCategory(tabControl1);
            AddTabPage(form, "กลุ่มสินค้าหลัก");
        }

        private void mnuProductSubCategory_Click(object sender, EventArgs e)
        {
            frmProductSubCategory form = new frmProductSubCategory(tabControl1);
            AddTabPage(form, "กลุ่มสินค้าย่อย");
        }

        private void mnuSupplierType_Click(object sender, EventArgs e)
        {
            frmSupplierType form = new frmSupplierType(tabControl1);
            AddTabPage(form, "ชนิดของ Supplier");
        }

        private void supplierToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmSupplier form = new frmSupplier(tabControl1);
            AddTabPage(form, "Supplier");
        }

        private void mnuPayment_Click(object sender, EventArgs e)
        {
            frmPaymentTerm form = new frmPaymentTerm(tabControl1);
            AddTabPage(form, "การจ่าย");
        }

        private void mnuProduct_Click(object sender, EventArgs e)
        {
            frmProduct form = new frmProduct(tabControl1);
            AddTabPage(form, "รายการสินค้า");
        }

        private void mnuSupplierProduct_Click(object sender, EventArgs e)
        {
            frmSupplierProduct form = new frmSupplierProduct(tabControl1);
            AddTabPage(form, "รายการสินค้าของ Supplier");
        }

        private void mnuExitProgram_Click(object sender, EventArgs e)
        {
            if (DialogResult.Yes == MessageBox.Show("คุณต้องการออกจากโปรแกรมใช่หรือไม่", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
            {
                Application.Exit();
                Environment.Exit(0);
            }
        }


        private void tabControl1_ControlRemoved(object sender, ControlEventArgs e)
        {

        }

        internal void RemoveTab(Form form)
        {
           
        }







    }
}
